package com.lvt.design.pattern.module.stat.v1;

import java.util.concurrent.TimeUnit;

/**
 * @author LT
 * @date 2023年02月22日 22:30
 */
public class UserController {
    // 应用场景：统计注册和登陆的响应时间和访问次数

    private Metrics metrics;

    public UserController() {
        metrics.startRepeatedReport(60, TimeUnit.SECONDS);
    }

    public void register(String telephone, String password) {
        long startTimeStamp = System.currentTimeMillis();
        metrics.recordTimestamp("register", startTimeStamp);
        //...
        long respTime = System.currentTimeMillis() - startTimeStamp;
        metrics.recordResponseTime("register", respTime);
    }

    public void login(String telephone, String password) {
        long startTimeStamp = System.currentTimeMillis();
        metrics.recordTimestamp("login", startTimeStamp);
        //...
        long respTime = System.currentTimeMillis() - startTimeStamp;
        metrics.recordResponseTime("login", respTime);
    }

}
